Write a Java program that would input three numbers from the user and print sum, then the first number, then the 2nd number followed by 3rd number. If user enters 10, 20, 30. then output should be 60, 10, 20, 30.
import java.util.Scanner;
public class Lab8q4{
public static void main ( String [] args ){
int [] number = new int [3];
int c = 0, sum=0;
Scanner input = new Scanner ( System.in );
System.out.println("Enter 3 numbers");
while(c<3){
number = input.nextInt();
sum = sum + number ;
++c;
}
System.out.println("SUM : "+sum);
c=0;
while(c<3){
System.out.println(number);
++c;
}
}
}
Write a Java program that would input ten numbers from the user and print the ten numbers in reverse order. If user enters 20, 10, 30, 15. Then output should be 15, 30, 10, 20.
import java.util.Scanner;
public class Lab8q5{
public static void main ( String [] args ){
int [] number = new int [3];
int c = 0, sum=0;
Scanner input = new Scanner ( System.in );
System.out.println("Enter 3 numbers");
while(c<3){
number = input.nextInt();
sum = sum + number ;
++c;
}
c=2;
while(c>=0){
System.out.println(number);
--c;
}
}
}
these are some simple java programs that may help you. ##6## A leading newspaper pays all their freelance writers at a rate of Tk. 500 per published article. Draw the flowchart for a program that will read the number of published articles for one writer, and print the total monthly fees for that writer.
/* time : 5.56pm
* author: Anik*/
import java.util.Scanner;
public class Faraz6 {
public static void main (String [] args) {
Scanner input= new Scanner (System.in);
System.out.println("Input Number(s) Article");
int a, fees;
a= input.nextInt();
fees= (a*500);
System.out.println("Total Fees: "+fees);
}
}
##7##Write a program that takes as input your final marks and shows as output the letter grade.
/*Time: 9:28pm
* Author: Anik Das*/
import java.util.Scanner;
public class Faraz7{
public static void main (String [] args){
Scanner input=new Scanner (System.in);
int n=0;
System.out.println("Enter your final marks");
n=input.nextInt();
if (n>=90){
System.out.println("Your Latter Grade is A");
}else{
if (n>=85){
System.out.println("Your Latter Grade is A-");
}else{
if (n>=80){
System.out.println("Your Latter Grade is B+");
}else{
if (n>=75){
System.out.println("Your Latter Grade is B");
}else{
if (n>=70){
System.out.println("Your Latter Grade is B-");
}else{
if (n>=65){
System.out.println("Your Latter Grade is C+");
}else{
if (n>=60){
System.out.println("Your Latter Grade is C");
}else{
if (n>=57){
System.out.println("Your Latter Grade is C-");
}else{
if (n>=55){
System.out.println("Your Latter Grade is D+");
}else{
if (n>=52){
System.out.println("Your Latter Grade is D");
}else{
if (n>=50){
System.out.println("Your Latter Grade is D-");
}else{
System.out.println("Your Latter Grade is F");
}
}
}
}
}
}
}
}
}
}
}
}
}
##8##. Write a flowchart for a program that performs four functions of a calculator. The program should request the user to enter a floating-point number, an operator and another floating-point number. It should then carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two floating-point numbers. Finally, it should display the result.
/*time: 9.59pm
* autthor: Anik Das
* Question: Write a flowchart for a program that performs four functions of a calculator.
* The program should request the user to enter a floating-point number,
* an operator and another floating-point number.
* It should then carry out the specified arithmetical operation:
* adding, subtracting, multiplying, or dividing the two floating-point numbers.
* Finally, it should display the result.*/
import java.util.Scanner;
public class Faraz8{
public static void main (String [] args){
float n, a, s;
Scanner input= new Scanner (System.in);
System.out.println("ENTER 1ST NUMBER");
n= input.nextFloat();
System.out.println("ENTER 2ND NUMBER");
a= input.nextFloat();
System.out.println("ENTER OPERATOR.ENTER 0 FOR ADDITION, 1 FOR SUBSTRUCTION, 2 FOR MULTIPLICATION, 3 FOR DIVISIOIN ");
String p;
int x=input.nextInt();
if (x==0){
s=n+a;
System.out.println("YOUR RESULT IS : "+s);
}else{
if (x==1){
s=n-a;
System.out.println("YOUR RESULT IS : "+s);
}else{
if (x==2){
s=n*a;
System.out.println("YOUR RESULT IS : "+s);
}else{
if (x==3){
s=n/a;
System.out.println("YOUR RESULT IS : "+s);
}else{
System.out.println("WRONG OPERATOR");
}
}
}
}
}
}
##1## Write a program to determine whether a number is odd or even.
/* Time: 5.10pm
* author: Anik
* Question:Write a program to determine whether a number is odd or even.*/
import java.util.Scanner;
public class Faraz1{
public static void main (String [] args){
Scanner input = new Scanner (System.in);
System.out.println("Enter your number");
int n=0;
n = input.nextInt();
if (n%2==0){
System.out.println("THE NUMBER IS EVEN");
}else{
System.out.println("THE NIMBER IS ODD");
}
}
}
##2##Write a program that takes three numbers input from the user and find the maximum and the minimum?
/*Time: 5.20pm
* Author: Anik Das
* Question:Write a program that takes three numbers input from the user
* and find the maximum and the minimum?*/
import java.util.Scanner;
public class Faraz2{
public static void main (String [] args){
Scanner input = new Scanner(System.in);
int a=0, max=0, min=0, c=1, d=2;
System.out.println("Please enter number 1");
a= input.nextInt();
max=a;
min=a;
while (c<=2){
System.out.println("Please enter number "+d);
a= input.nextInt();
if (a>=max){
max=a;
c=c+1;
d=d+1;
}else{
if (a<=min){
min=a;
c=c+1;
d=d+1;
}else{
c=c+1;
d=d+1;
}
}
}
System.out.println("MAX : "+max);
System.out.println("MIN : "+min);
}
}
##3##. Write a program that takes five number input from user and determine their addition and average.
/*time: 5:37pm
* author: Anik das
* question: Write a program that takes five number input from user
* and determine their addition and average.*/
import java.util.Scanner;
public class Faraz3{
public static void main (String [] args){
Scanner input = new Scanner(System.in);
int a=0, c=1, sum=0, avg=0;
while (c<=5){
System.out.println("Enter Number "+c);
a = input.nextInt();
sum = sum+a;
c=c+1;
}
avg=sum/5;
System.out.println("ADDITION : "+sum);
System.out.println("AVERAGE : "+avg);
}
}
##4##Write a program that finds CGPA given credits and grade of n courses where n is the user input.
/* Time: 11.46
* date: 11-02-2011
* Author: Anik Das
*question: Write a program that takes five number input from
* user and determine their addition and average.*/
import java.util.Scanner;
public class Faraz4 {
public static void main (String [] args) {
Scanner input = new Scanner (System.in);
int c, cr, tcr;
double gr, qp, tqp, gpa;
c=1;
tqp=0;
cr=0;
gr=0;
gpa=0.0;
tcr=0;
int n=0;
System.out.println("Enter Number of courses(n)");
n=input.nextInt();
while (c<=n)
{System.out.println("Enter Number of credits for course No. "+c);
cr = input.nextInt();
System.out.println("Enter Grade for course "+c);
gr = input.nextDouble();
qp = cr * gr;
tqp = tqp + qp;
tcr = tcr +cr;
c = c + 1;
}
gpa = (tqp/tcr);
System.out.println("Your GPA for Four courses is: " + gpa);
}
}
##5## Write a program for finding area of a rectangle given height and width.
/* time: 5.54pm
* author: Anik Das
* question: Write a program for finding area of a rectangle given height and width.*/
import java.util.Scanner;
public class Faraz5{
public static void main (String [] args){
Scanner input= new Scanner (System.in);
double w, h, area;
System.out.println("enter Width");
w= input.nextDouble();
System.out.println("enter Height");
h= input.nextDouble();
area= w*h;
System.out.println("Area of the Rectangle is "+area);
}
}