import java.util.Scanner; public class Javaprogram16 { public static void main(S
ID: 3829205 • Letter: I
Question
import java.util.Scanner;
public class Javaprogram16
{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
double a,b,x;
System.out.println("Enter a integer");
a= in.nextInt();
System.out.println("Enter a another integer");
b= in.nextInt();
if(a==0)
if(b==0)
System.out.println("All solution");
else
System.out.println("No Solution ");
else
{
System.out.println("One solution");
x = -b/a;
System.out.println("x = " +x);
}
}
}
Change this linear equation so it can have three methods in java
all solution
no solution
one solution
Explanation / Answer
Please let me know in case of any issue.
import java.util.Scanner;
public class Javaprogram16
{
public static void allSolution(){
System.out.println("All solution");
}
public static void noSolution(){
System.out.println("No Solution ");
}
public static void oneSolution(double a, double b){
System.out.println("One solution");
double x = -b/a;
System.out.println("x = " +x);
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
double a,b;
System.out.println("Enter a integer");
a= in.nextInt();
System.out.println("Enter a another integer");
b= in.nextInt();
if(a==0)
if(b==0)
allSolution();
else
noSolution();
else
{
oneSolution(a, b);
}
in.close();
}
}
/*
Sample run:
Enter a integer
6
Enter a another integer
3
One solution
x = -0.5
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.