Is there anyway to solve below problem in Java?
Wherever there is int it gives an error! It's not only line 20! it give an runtime error everywhere get int after string! or even before read string!
cities[i] = sc.next(); //This way does not work!!!!
==============
input
San Francisco Las Vegas 8 San Diego Los Angeles San Francisco San Jose Sacramento Santa Barbara Las Vegas Pheonix 8 19 0 1 0 3 1 0 1 2 1 4 1 3 2 1 2 5 2 6 2 7 3 7 3 0 3 1 4 7 4 1 5 2 6 2 7 2 7 3
==============
Error:
==============
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Solution.main(myFuncs.java:20)
=======================
==============
import java.io.*;
import java.util.*;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class myFuncs{
public static void main(String arg[]) {
Scanner sc = new
Scanner(System.in);
String s1, s2;
s1 = sc.nextLine();
//first city
s2 = sc.nextLine();
//second city
int n = sc.nextInt();
//total number of cities
String cities[] = new
String[n];
for (int i = 0; i <
n; i++) {
cities[i] = sc.nextLine(); //getting each city and storing
them
}
n = sc.nextInt();
int e =
sc.nextInt();
int adj[][] = new
int[n][e];
for (int i = 0; i <
n; i++)
for (int j = 0; j < e; j++)
adj[i][j] = 0;
for (int i = 0; i <
e; i++) {
int c1 = sc.nextInt();
int c2 = sc.nextInt();
adj[c1][c2] = 1;
adj[c2][c1] = 1;
}
int index1 = -1, index2 = -1;
for (int i = 0; i
< n; i++) {
if (cities[i].equals(s1)) index1 = i; //storing the index of first
city
if (cities[i].equals(s2)) index2 = i; //storing the index of second
city
}
adj[index1][index2] =
0;
adj[index2][index1] =
0;
System.out.println(cities[index1] + " " + index1);
System.out.println(cities[index2] + " " + index2);
if (bfs(adj, index1,
index2, n)) System.out.println("true");
else
System.out.println("false");
}
public static boolean bfs(int adj[][], int source, int dest, int V) {
boolean visited[] = new boolean[V];
LinkedList < Integer > queue = new LinkedList < Integer > ();
visited[source] =
true;
//visited[dest]=true;
queue.add(source);
while (queue.size()
!= 0) {
int s = queue.poll();
if (queue.size() != 0)
queue.remove();
System.out.print(s + " ");
for (int i = s; i < V; i++) {
if (adj[s][i] == 1 && !visited[i]) {
visited[i] = true;
queue.add(i);
if (i == dest) return true;
}
}
}
return false;
}
}
In: Computer Science
IN C++ PLEASE:
(1) Extend the ItemToPurchase class per the following
specifications:
(2) Create three new files:
Build the ShoppingCart class with the following specifications. Note: Some can be function stubs (empty functions) initially, to be completed in later steps.
In: Computer Science
According to the author, what three kinds of information can be learned from international comparisons of health care systems and What sorts of questions might arise about health care politics being common or different among countries? (500 words) In your own words No plagiarizm
In: Economics
In your reading assignment, “Engaging With Children and Young People” by Mary Kellett, the author suggested methods for more effective communication.
Mention three “pearls” that you will utilize in practice involving general and/or specific pediatric populations.
https://epubs.scu.edu.au/cgi/viewcontent.cgi?article=1029&context=ccyp_pubs/
In: Nursing
In: Statistics and Probability
Find an article relating to Cost of Capital or Capital Budgeting from any medium, briefly summarize the article, explain how you found the article particularly useful or timely, and give your personal reactions to the article. Be sure to provide the title of the article, the author(s), and the reference for the article.
In: Finance
In: Nursing
I recently did an experiment where we had to discover the rate order of the sufrace area of magnesium and hydrochloric acid as well as the activation energy. The point of the experiment was to discover the kinetic parameters of a heterogenous reaction. As I was writing my lab report, I uncovered a similiar experiment however the rate order for their experiment for hydrochloic acid was 2 when mine came out as 1. So I was curious as to how is it possible for the same experiment to produce different rate orders? What factors could change the rate order of a reactant? Thank you for any help you can give me.
In: Chemistry
Choose a binomial probability experiment. You could flip a coin, or toss a basketball from the free throw line and see if you make the shot or miss, or choose another experiment where the outcome is a success or failure (only two possible outcomes.)
1) Make a guess about the probability of success before doing the experiment.
2) Repeat the experiment 50 times, and record the results.
3) Calculate the empirical probability of success, and compare it to your original guess. Were you close or were you far off?
4) Write a paragraph explaining how you did the experiment and comparing your results to your guess
In: Statistics and Probability
1 (a) A pair of dice is rolled, and the number that appears uppermost on each die is observed. Refer to this experiment and find the probability of the given event. (Enter your answer as a fraction.)
The sum of the numbers is either 7 or 11.
(b) An experiment consists of selecting a card at random from a 52-card deck. Refer to this experiment and find the probability of the event. (Enter your answer as a fraction.)
A face card (i.e., a jack, queen, or king) is drawn.
(c) An experiment consists of selecting a card at random from a 52-card deck. Refer to this experiment and find the probability of the event. (Enter your answer as a fraction.)
A black face card is not drawn.
In: Statistics and Probability