0% found this document useful (0 votes)
33 views

Programming Practice For Begginners

This document contains homework assignments on string and math functions in Java, with 7 tasks ranging from simple print statements to calculating quadratic roots, and notes emphasizing using functions instead of hard coding and showing sample outputs. The tasks include manipulating strings, generating random numbers, taking user input, and solving quadratic equations based on formulas provided. Solutions and sample outputs are given for each task to demonstrate the expected functionality.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Programming Practice For Begginners

This document contains homework assignments on string and math functions in Java, with 7 tasks ranging from simple print statements to calculating quadratic roots, and notes emphasizing using functions instead of hard coding and showing sample outputs. The tasks include manipulating strings, generating random numbers, taking user input, and solving quadratic equations based on formulas provided. Solutions and sample outputs are given for each task to demonstrate the expected functionality.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

OOP

MIT

Fall 2012

The difference between stupidity and genius is that genius has its limits. Albert Einstein

Homework 03
[String and Math Functions, General Programming Practice]
Note1: Output is made clear by showing boxes so that spaces can be counted.
Note2: Dont do hard coding in task use formulas and functions to generalize your programs.
Note3: In task 7 output on right hand side is of two different runs of the program
Task 1:
Complete code written inside main function to show output given on right hand side?
String space="
";
System.out.println("*");
System.out.println("*"+space.substring(0,0)+"*");

*
* *
*
*
*
*
*
*
*
*
* * * * * * *

Task 2:
Complete code written inside main function to show output given on right hand side?
String space="
";
System.out.println("*");
System.out.println("*"+space.substring(0,0)+"*");

*
*
*

*
*

*
*
* ** * * * * * *

Use Random Function for Next 3 Tasks


Task 3
Print 5 real values between 200 and 300
Task 4
Print 5 integer values between -200 & -100
Task 5
Print 5 capital alphabets
Help: Capital alphabets have ASCII code from 65 to 90. Type cast in char to show alphabet like
System.out.println((char)65);//will show A as output
Task 6
Write a program to take full name as input from user using nextLine method of Scanner class. Full
name includes first name & last name like "Muhammad Hamid". Take two String variables firstName
& lastName. Assign first part of name in firstName & second part in lastName. Finally display them
in separate line. Dont hard code use appropriate functions from String class.
Task 7:
Write program to calculate quadratic roots using formula

and

. Take a, b, c as double values from user, calculate x1, x2 roots and

display answer. See the sample run on right hand side.

Resource Person: Abdul Mateen

A:2
B:5
C:3
X1:-1.0
A:4
B:9
C:5
X1:-1.0

X2:-1.5

X2:-1.25

Page 1 of 1

You might also like